<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
require_once ("Online_message.php");

$bAuth = $USER->IsAuthorized();
$arParams["stream_id"] = false;
$arParams["author_id"] = false;

$arParams["USE_CAPTCHA"] = (($arParams["USE_CAPTCHA"] != "N" && !$USER->IsAuthorized()) ? "Y" : "N");

if ($bAuth)
{
	$arFilter = array("ENTITY_TYPE"=> "U", "ENTITY_ID" => $USER->GetID());
}
else
{
	$hash = $APPLICATION->get_cookie("CONSULT_USER_SID");
	$arFilter = array("ENTITY_TYPE"=> "G", "ENTITY_ID" =>$hash);
}
$obConsUser = new CConsultUser;
$dbUser = $obConsUser->GetList (array(), $arFilter);
if ($arUser = $dbUser->Fetch())
{
	$arParams["author_id"] = $arUser["ID"];
	$ob_stream = new COnline_stream;
	$dbStream = $ob_stream->GetList(array(), array("ENTITY_ID"=> $arParams["author_id"]));
	if ($arStream = $dbStream -> Fetch())
	{
		$arParams["stream_id"] = $arStream["ID"];
	}
}

if (!$arParams["stream_id"] || !$arParams["author_id"])
{
	$arResult["NEED_REG"] = Y;
	if ($arParams["USE_CAPTCHA"] == "Y")
		$arResult["capCode"] =  htmlspecialchars($APPLICATION->CaptchaGetCode());
}



require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
?>